#ifndef XIAC_First
#define XIAC_First
#ifdef __GNUG__
#pragma interface
#endif

extern "C" {
#   include "X11.h"
	long strtol(const char*, char**, int base);
	int atoi(const char*);
};

#include "IAC.h"

class SeqCollection;

//---- XIAC --------------------------------------------------------------------

class XIAC : public IACImpl {
public:
	XIAC(IAC *sc, XDisplay *d, XWindow w);
	~XIAC();
	int Open(const char*);
	int Close(const char*);
	int LookupName(const char *nm, bool start);
	int SendTo(int to, int serial, const char *buf, int len);
	int SendReply(int to, int serial, int code, const char *buf, int len);
	int Broadcast(int serial, const char *buf, int len);
	int Poll(int serial, const char *buf, int len);
	bool HandleEvent(XEvent &ev);
	void HandleError(XErrorEvent *ev);
private:
	void ProcessRequest(XEvent *ev);
	char *GetProperty(XWindow win, Atom &atom, int del, u_long *len);
	void VerifyClients();
	XWindow Find(const char *nm);
	void UpdateClient(const char *nm, XWindow w);
	void TestClients();
	XWindow FindWin(const char *nm);
	int Lookup(const char *nm);
private:
	Atom et, registry, comm;
	XDisplay *disp;
	XWindow win, root;
	SeqCollection *clients;
	bool freewin, goterror;
};

#endif

